package cn.kmia.hrm;

import cn.kmia.hrm.service.basicData.*;
import cn.kmia.hrm.util.SSOUtil;
import net.sf.ehcache.CacheManager;
import org.nutz.dao.Dao;
import org.nutz.dao.util.Daos;
import org.nutz.ioc.Ioc;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.NutConfig;
import org.nutz.mvc.Setup;

/**
 * @项目：hrm
 * @作者：4K
 * @描述：
 * @日期：created in 12:57 2018/1/30
 */
public class MainSetup implements Setup {

    private static final Log log = Logs.get();

    @Override
    public void init(NutConfig nutConfig) {
        Ioc ioc = nutConfig.getIoc();
        Dao dao = ioc.get(Dao.class);
        // 若数据库中表不存在，则自动建表
        Daos.createTablesInPackage(dao, "cn.kmia.hrm", false);
        CacheManager cacheManager = ioc.get(CacheManager.class);
        // 从SSO获取组织机构信息
        SSOUtil.setAccess_Token();
        SSOUtil.setSSO_Orgs();
        // 设置岗位关联信息
        PostLinkInfoService postLinkInfoService = ioc.get(PostLinkInfoService.class);
        postLinkInfoService.updatePostLinkInfo();
        postLinkInfoService.updatePostNameRequire();
        // 设置岗位性质信息
        PostTypeInfoService postTypeInfoService = ioc.get(PostTypeInfoService.class);
        postTypeInfoService.updatePostTypeInfo();
        // 设置岗位区域信息
        PostAreaInfoService postAreaInfoService = ioc.get(PostAreaInfoService.class);
        postAreaInfoService.updatePostAreaInfo();
        // 设置岗位区域视线状况信息
        PostSignInfoService postSignInfoService = ioc.get(PostSignInfoService.class);
        postSignInfoService.updatePostSignInfo();
        // 设置岗位属性信息
        PostNatureInfoService postNatureInfoService = ioc.get(PostNatureInfoService.class);
        postNatureInfoService.updatePostNatureInfo();
        // 设置岗位班制信息
        PostShiftArrangementService postShiftArrangementService = ioc.get(PostShiftArrangementService.class);
        postShiftArrangementService.updatePostShiftArrangement();
    }

    @Override
    public void destroy(NutConfig nutConfig) {

    }
}
